package core.utils.communicationTester;

import java.net.BindException;
import java.net.MalformedURLException;

import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.transport.Connector;

public class Server {
	private Connector connector = null;

	public void setUp(String locatorURI) throws BindException {
		try {
			InvocationHandler invocationHandler = new InvocationHandlerImpl();
			InvokerLocator invokerLocator = null;

			invokerLocator = new InvokerLocator("socket://" + locatorURI);

			connector = new Connector(invokerLocator);
			connector.create();
			connector.addInvocationHandler(locatorURI, invocationHandler);
			if (!connector.isStarted()) {
				connector.start();
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void shutdownServer() {
		if (connector != null) {
			connector.stop();
		}
	}
}
